package tech.moya.flexbase.core.ui
{
	import flash.filesystem.File;
	
	import mx.collections.ArrayCollection;
	
	import tech.moya.flexbase.beans.Connection;
	import tech.moya.flexbase.components.QueryPanel;
	import tech.moya.flexbase.core.BaseContext;
	
	public class ApplicationContext
	{
		private static var applicationContext:ApplicationContext;
		public static var flexBase:FlexBaseMain;
		private var currentBaseContxt:BaseContext;
		
		public function addConn2TreeMenu(connection:Connection):void{
		
			if(flexBase != null && flexBase.connectionList.dataProvider != null){
				var arrCollection:ArrayCollection = ArrayCollection(flexBase.connectionList.dataProvider);
				arrCollection.addItem(connection);
				
			}
			
		}
		
		public function get CurrentBaseContext():BaseContext{
			return currentBaseContxt;
		}
		
		public function setOutputText(txt:String){
			flexBase.outputTxtArea.text = txt;
		}
		
		public function ApplicationContext(x=null)
		{
			//flexBase = FlexBaseMain(new SystemManager().application);
		}
		
		public static function getCurrentApplicationContext():ApplicationContext{
			if(applicationContext == null)
				applicationContext = new ApplicationContext();
				
			return applicationContext;	
		}
		
		public function openQueryPanel(filePath:String):BaseContext{
			
			var qPanel:QueryPanel =  new QueryPanel(new File(filePath).name)
			qPanel = QueryPanel(flexBase.qPanelNav.addChild(qPanel));
			currentBaseContxt = BaseContext.getQueryPanelContext(qPanel,filePath);
			return currentBaseContxt;
			
			
		}
		
		public function changeQueryPanel(panel:QueryPanel):void{
			currentBaseContxt = BaseContext.getQueryPanelContext(panel)
		} 

	}
}